package com.example.administrator.yunniuusedcar.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.common.base.Global;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.ArticleInfoAdapter;
import com.example.administrator.yunniuusedcar.adapter.Info02ActionAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.WZ_ArticleInfoBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.ArrayList;

import okhttp3.Call;
//private RecyclerView recyclerView;

/**
 * Created by Administrator on 2017/12/6.
 * 资讯  活动资讯
 */

public class FragmentInfor02 extends Fragment {
    private RecyclerView recyclerView6;    //Fragment
    private ArticleInfoAdapter infoAdapter;
    private ArrayList listDatas;

//    ArrayList<WZ_ArticleInfoBean.Data> listDatas = new ArrayList();

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        TextView textView = new TextView(getContext());
        textView.setText(getContext().getClass().getSimpleName());  // 获取名字
        textView.setTextColor(Color.RED);
        textView.setTextSize(18);
        textView.setGravity(Gravity.CENTER);
/////
        View view = inflater.inflate(R.layout.item_recycleview2, null);           //fragment_choosecar02_informationi
        recyclerView6 = view.findViewById(R.id.recycler_view6);

        recyclerView6.setLayoutManager(new LinearLayoutManager(getContext()));
        //创建数据
        listDatas = new ArrayList();
        initUloadMenuInfor();    //// 文章详情( 获取数据 )


/////
        return view;
    }

    private void initUloadMenuInfor() {    // 加载数据

        String ul = IHttpService.HOST_URL + "Article/getInfo";    // 文章详情

        OkHttpUtils.post().url(ul).addParams("sign", IHttpService.SignVal).addParams("article_id", "4").build().execute(new StringCallback() {     //.addParams("type","1")

            @Override
            public void onError(Call call, Exception e, int id) {
                          Global.showToast("请求超时！"+ e.getMessage());
                      System.out.println("-----====----------A"+ e);
            }

            @Override
            public void onResponse(String response, int id) {
                //        Global.showToast("====="+response);
                      System.out.println("-----====-----------A1"+response);
                Gson js = new Gson();
                WZ_ArticleInfoBean wzArticleInfoBean = js.fromJson(response, WZ_ArticleInfoBean.class);
                listDatas.add(wzArticleInfoBean);
//                Info02ActionAdapter info02ActionAdapter = new Info02ActionAdapter(getContext(),listDatas);
                        infoAdapter = new ArticleInfoAdapter(getContext(), R.layout.fragment_choosecar02_information, listDatas);
                recyclerView6.setAdapter(infoAdapter);
                //   infoAdapter.setdata(listDatas);

            }
        });
    }
}
